home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1826 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.0 KB  |  97 lines

  1. Path: cnn.iper.net!usenet
  2. From: giampo@imar.net (gianluca porcarelli)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: ******** Questions about MSVC++ programming ********
  5. Date: Wed, 10 Jan 1996 13:31:57 GMT
  6. Organization: IPER-NET Internet Services +39-541-378202
  7. Message-ID: <4d0ge7$8k8@cnn.iper.net>
  8. References: <4cbm3n$1r4i@mercury.cc.uottawa.ca>
  9. NNTP-Posting-Host: giampo.imar.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. jxie@csi.uottawa.ca (Jun Xie) wrote:
  13.  
  14. >Hi,
  15.  
  16. >I am new to the MSVC++ Ver 1.5 and MFC and have following questions.
  17. >I appreciate it very much if you could answer any one of them or
  18. >tell me the place (book, webpage, online help etc) where I can find
  19. >the answers.
  20. >............
  21. >4) How to get the current width and height of the client device context?
  22. >   I hope my graphics images drawn on the DC are proportional to its size.
  23. >   That means if you change the size of the window, the graphics image will
  24. >   change accordingly. I tried to use GetDeviceCaps() as follows, but the
  25. >   width and heigth returned are always 1024 and 768 respectively.
  26.  
  27. >    void CXXXView::OnXXX()
  28. >    {
  29. >        // TODO: Add your command handler code here
  30. >        CClientDC dc(this);
  31. >        int width, height;
  32.  
  33. >        width = dc.GetDeviceCaps(HORZRES);
  34. >        height = dc.GetDeviceCaps(VERTRES);
  35. >            .
  36. >            .
  37. >            .
  38. >    } 
  39.  
  40. >Thank you for your attention.
  41.  
  42. Try to use  "GetClientRect(clientRect)" in your function clientRect
  43. return the size of the client area.
  44. This example try to draw a bitmap in the client area.
  45.  
  46. void CPrimaView::OnDraw(CDC* pDC)
  47. {
  48.     CRect clientRect;
  49.     CSize Ampiezza(640, 396);
  50.     CSize AmpiezzaSchermo;
  51.     GetClientRect(clientRect); // device coords 
  52.     BOOL vero;
  53.     double appXY, appYX, appX, appY;
  54.     
  55. //   Ampiezza = m_bmSize;
  56.    appX = Ampiezza.cx;
  57.     appY = Ampiezza.cy;
  58.     AmpiezzaSchermo.cx = clientRect.Width();
  59.     AmpiezzaSchermo.cy = clientRect.Height();
  60.     appXY = (double)(appX / appY);
  61.     appYX = (double)(appY / appX);
  62.     
  63.     if (Ampiezza.cx > Ampiezza.cy) {
  64.             AmpiezzaSchermo.cx = (int)(AmpiezzaSchermo.cy * appXY);
  65.             if (AmpiezzaSchermo.cx > clientRect.Width())  {
  66.                         AmpiezzaSchermo.cx = clientRect.Width();
  67.                            AmpiezzaSchermo.cy = (int)(AmpiezzaSchermo.cx * appYX);
  68.                            }
  69.            }
  70.        else {
  71.             AmpiezzaSchermo.cy = (int)(AmpiezzaSchermo.cx * appYX);
  72.               if (AmpiezzaSchermo.cy > clientRect.Height()) {
  73.                         AmpiezzaSchermo.cy = clientRect.Height();
  74.                         AmpiezzaSchermo.cx = (int)(AmpiezzaSchermo.cy *
  75. appXY);
  76.                         }   
  77.             }
  78.                  
  79.     pDC->SetMapMode(MM_TEXT);
  80.     pDC->DPtoLP(&Ampiezza);
  81.     pDC->DPtoLP(&AmpiezzaSchermo);   // logical
  82.     vero = pDC->StretchBlt(0, 0, AmpiezzaSchermo.cx,
  83. AmpiezzaSchermo.cy,    // disegna solamente una figura della  
  84.                 m_pDisplayMemDC, 0, 0, Ampiezza.cx, Ampiezza.cy,
  85. SRCCOPY);   // grandezza della figura caricata cioΦ 
  86.           
  87. }
  88.  
  89. ==============================================
  90. Gianluca Porcarelli
  91.  
  92. Chiaravalle (ANCONA)     
  93.         (ITALY)
  94. email:    giampo@imar.net
  95. =============================================
  96.  
  97.